//
//  AppDelegate.swift
//  Weibo
//
//  Created by xu on 2017/3/18.
//  Copyright © 2017年 xuantong. All rights reserved.
//

import UIKit



@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        //注册通知
        registerNotifcation()
        
        window = UIWindow (frame: UIScreen.main.bounds)
        
        window?.rootViewController = setupRootViewContoller()
        
        window?.backgroundColor = UIColor.white
        
        window?.makeKeyAndVisible()
    
    
        return true
    }

    
    private func registerNotifcation() {

        NotificationCenter.default.addObserver(self, selector: #selector(switchRootViewController), name: NSNotification.Name(rawValue: SWITCHROOTVIEWCONTROLLERNOTI), object: nil)
    }
    
    
    @objc private func switchRootViewController(n:NSNotification) {
        
        let vc = (n.object == nil ? WBWelcomeViewController(): WBTabBarController())
        window?.rootViewController = vc
        
        
    }
    
    private func setupRootViewContoller()-> UIViewController{
        return WBUserAccountViewModel.shared.userLogin ? WBWelcomeViewController() : WBTabBarController()
    }
    
      
    
    
}

